<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org">
<head>
    <meta charset="UTF-8">
    <link th:href="@{/css/bootstrap.min.css}" type="text/css" rel="stylesheet"/>
    <script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
    <script th:src="@{/js/jquery.md5.js}" type="text/JavaScript"></script>
    <script type="text/javascript" th:src="@{/js/bootstrap.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/jquery.validate.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/common.js}"></script>
    <script type="text/javascript" th:src="@{/js/layer/layer.js}"></script>
    <title>商品详情</title>
</head>
<body>
<script>
    $(function () {
        countDown();
    });

    function countDown() {
        var remainSeconds = $("#remainSeconds").val();
        var timeout;
        //秒杀还未开始
        if(remainSeconds > 0){
            $("#seckillButton").attr("disabled",true);
            timeout = setTimeout(function () {//一秒调用一次
                $("#countDown").text(remainSeconds - 1);
                $("#remainSeconds").val(remainSeconds - 1);
                countDown();
            },1000)
        }else if(remainSeconds == 0){
            $("#seckillButton").attr("disabled",false);
            if(timeout){//倒计时结束 秒杀进行中
                clearTimeout(timeout);
            }
            $("#seckillTip").html("秒杀进行中");
        }else {
            $("#seckillButton").attr("disabled",true);
            $("#seckillTip").html("秒杀已结束");
        }
    }
</script>
<div class="panel-default">
    <div class="panel-heading">秒杀商品详情</div>
    <div class="panel-body">
        <span th:if="${user} eq null">您还没有登陆！</span>
        <span>没有收货地址的提示</span>
    </div>
    <table class="table" id="goods">
        <tr>
            <td>商品名称</td>
            <td colspan="3" th:text="${goods.goodsName}"></td>
        </tr>
        <tr>
            <td>商品图片</td>
            <td colspan="3"><img th:src="@{${goods.goodsImg}}" width="200" height="200"></td>
        </tr>
        <tr>
            <td>秒杀开始时间</td>
            <td th:text="${#dates.format(goods.startDate,'yyyy-MM-dd HH:mm:ss')}"></td>
            <td id="seckillTip">
                <input type="hidden" id="remainSeconds" th:value="${remainSecond}">
                <span th:if="${seckillStatus} eq 0 ">秒杀倒计时:
                    <span th:text="${remainSecond}" id="countDown"></span>秒
                </span>
                <span th:if="${seckillStatus} eq 1 ">秒杀进行中</span>
                <span th:if="${seckillStatus} eq 2 ">秒杀已结束</span>
            </td>
            <td>
                <form id="seckillForm" method="post" action="/seckill/doSeckill">
                    <input type="hidden" name="goodsId" th:value="${goods.id}">
                    <button class="btn btn-primary btn-block" type="submit" id="seckillButton">立即秒杀</button>
                </form>
            </td>
        </tr>
        <tr>
            <td>商品原价</td>
            <td colspan="3" th:text="${goods.goodsPrice}"></td>
        </tr>
        <tr>
            <td>秒杀价</td>
            <td colspan="3" th:text="${goods.seckillPrice}"></td>
        </tr>
        <tr>
            <td>库存数量</td>
            <td colspan="3" th:text="${goods.stockCount}"></td>
        </tr>
    </table>
</div>
</body>
</html>